using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.ActiveRecord;
using NHibernate.Expression;

/// <summary>
/// Summary description for Site
/// </summary>
/// 

[ActiveRecord("Site")]
public class SiteDomain : ActiveRecordBase<SiteDomain>
{

    public static MatchMode Exact = MatchMode.Exact;
    public static MatchMode Anywhere = MatchMode.Anywhere;
    public static MatchMode End = MatchMode.End;
    public static MatchMode Start = MatchMode.Start;

    private int iD;

    [PrimaryKey(PrimaryKeyType.Identity)]
    public int ID
    {
        get { return iD; }
        set { iD = value; }
    }

    private String baseImageDir;

    [Property]
    public String BaseImageDir
    {
        get { return baseImageDir; }
        set { baseImageDir = value; }
    }

    private String cssFilename;

    [Property]
    public String CssFilename
    {
        get { return cssFilename; }
        set { cssFilename = value; }
    }

    private String siteCode;

    [Property]
    public String SiteCode
    {
        get { return siteCode; }
        set { siteCode = value; }
    }

    private String siteImageDir;

    [Property]
    public String SiteImageDir
    {
        get { return siteImageDir; }
        set { siteImageDir = value; }
    }

    private String domain;
    
    [Property]
    public String Domain
    {
        get { return domain; }
        set { domain = value; }
    }

    private bool isDefault;
    
    [Property]
    public bool IsDefault
    {
        get { return isDefault; }
        set { isDefault = value; }
    }

    private bool activeFlag;

    [Property]
    public bool ActiveFlag
    {
        get { return activeFlag; }
        set { activeFlag = value; }
    }

    private DateTime createdDate;

    [Property]
    public DateTime CreatedDate
    {
        get { return createdDate; }
        set { createdDate = value; }
    }


    private DateTime updatedDate;


    [Property]
    public DateTime UpdatedDate
    {
        get { return updatedDate; }
        set { updatedDate = value; }
    }

    private int createdUserID;

    [Property]
    public int CreatedUserID
    {
        get { return createdUserID; }
        set { createdUserID = value; }
    }

    private int updatedUserID;


    [Property]
    public int UpdatedUserID
    {
        get { return updatedUserID; }
        set { updatedUserID = value; }
    }



	public SiteDomain()
	{
		//
		// TODO: Add constructor logic here
		//
        this.CreatedDate = DateTime.Now;
        this.UpdatedDate = DateTime.Now;
	}

    public SiteDomain(String baseImage,String cssfile,String sitecode,String siteImage,String domain,bool isDefault,bool active,int createdUserID)
    {
        this.BaseImageDir=baseImage;
        this.CssFilename = cssfile;
        this.SiteCode = sitecode;
        this.SiteImageDir = siteImage;
        this.Domain = domain;
        this.IsDefault = isDefault;
        this.ActiveFlag = active;
        this.CreatedUserID = createdUserID;
        this.UpdatedUserID= createdUserID;
        this.CreatedDate = DateTime.Now;
        this.UpdatedDate = DateTime.Now;
    }

    public static void create_site(String baseImage, String cssfile, String sitecode, String siteImage, String domain, bool isDefault, bool active, int createdUserID)
    {
        SiteDomain site = new SiteDomain(baseImage,cssfile,sitecode,siteImage,domain,isDefault,active,createdUserID);
        site.Create();
    }

    public static void update_site(int id, String baseImage, String cssfile, String sitecode, String siteImage, String domain, bool isDefault, bool active, int updatedUserID)
    {
        SiteDomain site = SiteDomain.get_site(id);
        site.BaseImageDir = baseImage;
        site.CssFilename = cssfile;
        site.SiteCode = sitecode;
        site.SiteImageDir = siteImage;
        site.Domain = domain;
        site.IsDefault = isDefault;
        site.ActiveFlag = active;
        site.UpdatedUserID = updatedUserID;
        site.Update();
    }

    public static void delete_site(int id)
    {
        SiteDomain site = SiteDomain.get_site(id);
        site.Delete();
    }

    public static SiteDomain get_site(int id)
    {
        return FindByPrimaryKey(id);
    }

    public static SiteDomain get_site(string domain)
    {
        //SiteDomain[] site= FindAllByProperty("Domain",domain);

        //if (site.Length > 0 ) return site[0];

        return FindOne(Expression.Eq("Domain",domain));

        //return null;
    }

    public static SiteDomain[] get_all_site()
    {
        return FindAll();
    }


    public static SiteDomain[] search_site(String propertyName, String textSearch, NHibernate.Expression.MatchMode mode)
    {
        DetachedCriteria criteria = DetachedCriteria.For<SiteDomain>();
        criteria.Add(Expression.InsensitiveLike(propertyName, textSearch, mode));
        return FindAll(criteria, SiteDomain.Asc("ID"));
    }

    public static SiteDomain[] get_site_and_sort(String propertyName, String order)
    {
        DetachedCriteria avgWeight = DetachedCriteria.For<SiteDomain>();
        if (order == "ASC")
            return FindAll(avgWeight, Asc(propertyName));
        return FindAll(avgWeight, Desc(propertyName));
    }
}
